package com.tarena.lbs.basic.web.controller;

import com.tarena.lbs.base.protocol.exception.BusinessException;
import com.tarena.lbs.base.protocol.model.Result;
import com.tarena.lbs.basic.web.service.LoginService;
import com.tarena.lbs.pojo.basic.bo.AdminBO;
import com.tarena.lbs.pojo.basic.bo.UserBO;
import com.tarena.lbs.pojo.basic.param.UserTagsParam;
import com.tarena.lbs.pojo.basic.vo.UserVO;
import com.tarena.lbs.pojo.passport.param.AdminLoginParam;
import com.tarena.lbs.pojo.passport.param.UserLoginParam;
import com.tarena.lbs.pojo.passport.vo.LoginVO;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class LoginController {
    @Autowired
    private LoginService loginService;

    @PostMapping("/passport/admin/login")
    public Result<LoginVO> adminLogin(AdminLoginParam param) throws BusinessException {
        //调用业务层 判断登录结果,登陆成功 给我返回查询到 业务结果 AdminBO
        AdminBO adminBO = loginService.adminDoLogin(param);
        LoginVO vo = new LoginVO();
        BeanUtils.copyProperties(adminBO,vo);
        return new Result<>(vo);
    }

    //小程序登录
    @PostMapping("/passport/user/login")
    public Result<LoginVO> UserLogin(UserLoginParam param) throws BusinessException {
        //调用业务层 新增注册
        UserBO userBO = loginService.UserDoLogin(param);
        LoginVO vo = new LoginVO();
        BeanUtils.copyProperties(userBO,vo);
        return new Result<>(vo);
    }
    //查询用户详情
    @GetMapping("/basic/user/detail")
    public Result<UserVO> UserDetail() throws BusinessException {
        UserBO userBO = loginService.userDetail();
        UserVO vo = new UserVO();
        BeanUtils.copyProperties(userBO,vo);
        return new Result<>(vo);
    }

}
